from django.db import models


class Bill(models.Model):
    bill_id = models.BigAutoField(primary_key=True, db_comment='账单ID')
    bill_number = models.CharField(unique=True, max_length=50, db_comment='账单编号')
    payer_user = models.ForeignKey('users.User', models.DO_NOTHING, blank=True, null=True, db_comment='支付方用户ID')
    payer_company = models.ForeignKey('users.Company', models.DO_NOTHING, blank=True, null=True, db_comment='支付方企业ID')
    amount = models.DecimalField(max_digits=12, decimal_places=2, db_comment='金额')
    due_date = models.DateField(db_comment='应付日期')
    payment_date = models.DateField(blank=True, null=True, db_comment='实际支付日期')
    payment_status = models.CharField(max_length=20, db_comment='支付状态(未支付/已支付/部分支付/逾期/已关闭)')
    bill_type = models.CharField(max_length=50, db_comment='账单类型(租金/物业费/水费/电费/维修费/保洁费/停车费/其他)')
    bill_period = models.CharField(max_length=20, blank=True, null=True, db_comment='账单周期(如2025-07)')
    contract = models.ForeignKey('services.Contract', models.DO_NOTHING, blank=True, null=True, db_comment='关联合同ID')
    service_id = models.BigIntegerField(blank=True, null=True, db_comment='关联服务ID')
    remarks = models.TextField(blank=True, null=True, db_comment='备注')
    created_at = models.DateTimeField()
    updated_at = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'bill'
        db_table_comment = '账单表'

